package com.sfx.concurrent.demo.concurrent.Test.demo1;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-29
 * Time: 22:21
 */
@Slf4j(topic = "c.TestDemo2")
public class TestDemo2 {

    //锁对象建议使用final修饰的,因为锁对象不可以变,如果变了,锁的就不是相同的对象了
    private static final Object obj = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            synchronized (obj) {
                log.debug("获得锁");
                try {
                    obj.wait(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        Thread.sleep(1000);
        synchronized (obj) {
            log.debug("获得锁");
        }
    }
}
